﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Threading;
using System.Globalization;
using System.Resources;

using EHTWebsite.Code;

namespace EHTWebsiteProject
{
    public partial class TinTucs : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        private Int32 danhMucTinTucID = 15;
        private Int32 pageIndex = 1;
        private Int32 pageSize = 10000;
        private Int32 totalRecord = 0;

        public Int32 tinTucHotID = -1;
        public String tieuDeHot = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            String languageCode = "vi-VN";

            try
            {
                languageCode = Session[HangSo.LANGUAGE_CODE].ToString();

                if (languageCode == "en-us")
                    IsVN = false;
            }
            catch (Exception ex)
            {
            }

            //try
            //{
            //    danhMucTinTucID = Int32.Parse(Request.QueryString["DanhMucTinTucID"].ToString());
            //}
            //catch (Exception ex)
            //{

            //}

            try
            {
                pageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
            }
            catch (Exception ex)
            {

            }

            if (!Page.IsPostBack)
            {
                DanhMucTinTuc theDanhMucTinTuc = DanhMucTinTucProvider.GetDanhMucTinTucByDanhMucID(danhMucTinTucID);
 
                if (theDanhMucTinTuc == null)
                {
                    Response.Redirect("~/trang-chu.aspx");
                }

                //this.ltrTenDanhMucTinTuc.Text = (IsVN == true) ? theDanhMucTinTuc.TenDanhMucTinTucVN : theDanhMucTinTuc.TenDanhMucTinTucOther;
                //pageSize = this.PaggingControl1.PageSize;
                TinTuc theTinTucHot = TinTucProvider.GetTinTucByTinTucID(theDanhMucTinTuc.TinTucHotID);

                if (theTinTucHot != null)
                {
                    tinTucHotID = theTinTucHot.TinTucID;
                    tieuDeHot = FormatStringForUrl(theTinTucHot.TieuDeVN);

                    if (IsVN)
                    {
                        this.ltrNewsTitleHot.Text = theTinTucHot.TieuDeVN;
                        this.ltrMoTaHot.Text = theTinTucHot.TomTatVN;
                    }
                    else
                    {
                        this.ltrNewsTitleHot.Text = theTinTucHot.TieuDeOther;
                        this.ltrMoTaHot.Text = theTinTucHot.TomTatOther;
                    }
                }

                DataSet dsTinTucs = TinTucProvider.GetTinTucsByFillterForFrontEnd("", "", theDanhMucTinTuc.DanhMucTinTucID, pageIndex, pageSize, out totalRecord);
                this.rpNews.DataSource = dsTinTucs;
                this.rpNews.DataBind();

                //this.PaggingControl1.TotalRecord = totalRecord;
                //this.PaggingControl1.PageURL = "/tin-tuc/" + theDanhMucTinTuc.DanhMucTinTucID + "/" + FormatStringForUrl(theDanhMucTinTuc.TenDanhMucTinTucVN) + ".aspx";
            }

        }

        public String FormatStringForUrl(String input)
        {
            return HelpMethod.FormatStringForUrl(input);
        }
    }
}